package com.qiang.test08;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Demo01 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {

        //获取class对象
        Class sc = Class.forName("com.qiang.test08.Student");

        //获取有参构造方法
        Constructor cc = sc.getDeclaredConstructor(String.class);

        //使用方法
        //创建学生对象
        //构造方法，可以直接创建对象
        cc.setAccessible(true);
        Student zs = (Student) cc.newInstance("张三");
        System.out.println(zs);


    }
}
